package com.egao.api.controller.orderB;


import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.service.OperRecordService;
import com.egao.orderB.entity.Address;
import com.egao.orderB.service.AddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

//import com.egao.orderB.entity.Bill;
//import com.egao.orderB.service.BillService;

/**
 * api登录相关接口
 * Created by wangfan on 2019-05-29 下午 3:43.
 * http://localhost/swagger-ui.html
 */
@RequestMapping("/api/address")
@RestController
@Api(value = "货代运费报价",tags = {"货代运费报价"})
public class ApiAddressController extends BaseController {
    @Autowired
    private OperRecordService operRecordService;
    @Autowired
    private AddressService addressService;

    /**
     * 运费维护列表
     */
    @PreAuthorize("hasAuthority('orderB:address:list')")
    @PostMapping("/list")
    @ApiOperation(value = "货代运费报价列表",notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            "customerId:货代id \n" +
            "customerName:货代名称\n" +
            "province:省\n" +
            "city:市\n" +
            "district:县区\n" +
            "town:镇\n" +
            "address:详细地址\n" +
            "dock:码头\n" +
            "boxType:箱型\n" +
            "返回的字段:\n" +
            "id:id\n" +
            "organizationId:组织id\n" +
            "customerId:货代id\n" +
            "customerName:货代名称\n" +
            "province:省\n" +
            "city:市\n" +
            "district:县区\n" +
            "town:镇\n" +
            "address:详细地址\n" +
            "dock:码头\n" +
            "boxType:箱型\n" +
            "price:价格\n" +
            "driverPrice:司机价格\n" +
            "contact:联系人\n" +
            "contactPhone:联系电话\n" +
            "state:状态\n" +
            "remark:备注\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "updateTime:更新时间\n" +
            "updateUser:更新人\n" +
            "deleted:del(0正常 1删除)\n" +
            "addressFactoryList 工厂地址电话集合\n" +
            "",httpMethod = "POST")
    public JsonResult list(PageResult2<T> page, Address address, HttpServletRequest request)  throws Exception{
        return addressService.list(page, address, getLoginUser());
    }

    /**
     * 添加运费维护列表
     */
    @PreAuthorize("hasAuthority('orderB:address:list')")
    @PostMapping("/listAll")
    @ApiOperation(value = "货代运费报价列表",notes = "" +
            "",httpMethod = "POST")
    public JsonResult listAll(Address address, HttpServletRequest request)  throws Exception{
        return addressService.list(address, getLoginUser());
    }
    /**
     * 查找货代运费报价
     * 如果没有找到就去maintainFee表里去找
     */
    @PreAuthorize("hasAuthority('orderB:address:list')")
    @PostMapping("/searchAddressFee")
    @ApiOperation(value = "查找货代运费报价",notes = "" +
            "customerId:查询字段\n" +
            "customerName:客户地址模糊搜索 必填\n" +
            "dock:码头 必填\n" +
            "返回的字段:\n" +
            "id:id\n" +
            "organizationId:组织id\n" +
            "customerId:货代id\n" +
            "customerName:货代名称\n" +
            "province:省\n" +
            "city:市\n" +
            "district:县区\n" +
            "town:镇\n" +
            "address:详细地址\n" +
            "dock:码头\n" +
            "boxType:箱型\n" +
            "price:价格\n" +
            "driverPrice:司机价格\n" +
            "contact:联系人\n" +
            "contactPhone:联系电话\n" +
            "state:状态\n" +
            "remark:备注\n" +
            "ftype: 类型:address maintainFee\n" +
            "",httpMethod = "POST")
    public JsonResult searchAddressFee(Address address, HttpServletRequest request)  throws Exception{
        return addressService.searchAddressFee(address, getLoginUser());
    }

    /**
     * 添加运费报价
     */
    @PreAuthorize("hasAuthority('orderB:address:save')")
    @OperLog(value = "货代运费报价", desc = "平台添加货代运费报价", result = true)
    @PostMapping("/sszgSave")
    @ApiOperation(value = "平台添加货代运费报价",notes = "\n" +
            "customerId:货代id\n" +
            "customerName:货代名称\n" +
            "province:省\n" +
            "city:市\n" +
            "district:县区\n" +
            "town:镇\n" +
            "address:详细地址\n" +
            "dock:码头\n" +
            "boxType:箱型\n" +
            "price:价格\n" +
            "driverPrice:司机价格\n" +
            "contact:联系人\n" +
            "contactPhone:联系电话\n" +
            "remark:备注\n" +
            "{\"customerId\":\"128\",\n" +
            "\"province\":\"省\",\n" +
            "\"city\":\"市\",\n" +
            "\"district\":\"县区\",\n" +
            "\"town\":\"镇\",\n" +
            "\"address\":\"详细地址\",\n" +
            "\"dock\":\"码头\",\n" +
            "\"boxType\":\"箱型\",\n" +
            "\"price\":\"价格\",\n" +
            "\"remark\":\"备注\",\n" +
            "\"contact\":\"lxr\",\n" +
            "\"contactPhone\":\"1313131131\",\n" +
            "\"driverPrice\":\"112\",\n" +
            "\"addressFactoryList\":[{\"faddress\":\"1\",\"fphone\":\"2\"},{\"faddress\":\"11\",\"fphone\":\"22\"}]}\n" +
            "",httpMethod = "POST")
    public JsonResult sszgSave(@RequestBody Address address, HttpServletRequest request) {
        address.setState("已审核");
        return addressService.save(address, getLoginUser());
    }

    /**
     * 添加运费报价
     */
    @PreAuthorize("hasAuthority('orderB:address:save')")
    @OperLog(value = "货代运费报价", desc = "货代添加货代运费报价", result = true)
    @PostMapping("/customerSave")
    @ApiOperation(value = "货代添加货代运费报价",notes = "\n" +
            "customerId:货代id 必填\n" +
            "province:省\n" +
            "city:市\n" +
            "district:县区\n" +
            "town:镇\n" +
            "address:详细地址\n" +
            "dock:码头\n" +
            "boxType:箱型\n" +
            "driverPrice:司机价格\n" +
            "contact:联系人\n" +
            "contactPhone:联系电话\n" +
            "remark:备注\n" +
            "{\"customerId\":\"128\",\n" +
            "\"province\":\"省\",\n" +
            "\"city\":\"市\",\n" +
            "\"district\":\"县区\",\n" +
            "\"town\":\"镇\",\n" +
            "\"address\":\"详细地址\",\n" +
            "\"dock\":\"码头\",\n" +
            "\"boxType\":\"箱型\",\n" +
            "\"driverPrice\":\"司机价格\",\n" +
            "\"remark\":\"备注\",\n" +
            "\"contact\":\"lxr\",\n" +
            "\"contactPhone\":\"1313131131\",\n" +
            "\"addressFactoryList\":[{\"faddress\":\"1\",\"fphone\":\"2\"},{\"faddress\":\"11\",\"fphone\":\"22\"}]}\n" +
            "",httpMethod = "POST")
    public JsonResult customerSave(@RequestBody Address address, HttpServletRequest request) {
        address.setState("申请");
        address.setPrice("");
        return addressService.save(address, getLoginUser());
    }

    /**
     * 修改运费报价
     */
    @PreAuthorize("hasAuthority('orderB:address:update')")
    @OperLog(value = "货代运费报价", desc = "平台修改货代运费报价", result = true)
    @PostMapping("/update")
    @ApiOperation(value = "平台修改货代运费报价",notes = "" +
            "id:运费报价id 必填\n" +
            "province:省\n" +
            "city:市\n" +
            "district:县区\n" +
            "town:镇\n" +
            "address:详细地址\n" +
            "dock:码头\n" +
            "boxType:箱型\n" +
            "price:价格\n" +
            "driverPrice:司机价格\n" +
            "contact:联系人\n" +
            "contactPhone:联系电话\n" +
            "remark:备注\n" +
            "{\"id\":\"195\",\n" +
            "\"province\":\"省1\",\n" +
            "\"city\":\"市1\",\n" +
            "\"district\":\"县区1\",\n" +
            "\"town\":\"镇1\",\n" +
            "\"address\":\"详细地址1\",\n" +
            "\"dock\":\"码头1\",\n" +
            "\"boxType\":\"箱型1\",\n" +
            "\"price\":\"价格1\",\n" +
            "\"driverPrice\":\"221\",\n" +
            "\"contact\":\"lxr1\",\n" +
            "\"contactPhone\":\"11\",\n" +
            "\"remark\":\"备注1\",\n" +
            "\"addressFactoryList\":[{\"id\":\"2\",\"faddress\":\"11\",\"fphone\":\"21\"},{\"id\":\"3\",\"faddress\":\"111\",\"fphone\":\"221\"}]}\n" +
            "",httpMethod = "POST")
    public JsonResult update(@RequestBody Address address, HttpServletRequest request) {
        return addressService.update(address, getLoginUser());
    }

    /**
     * 修改运费报价
     */
    @PreAuthorize("hasAuthority('orderB:address:update')")
    @OperLog(value = "货代运费报价", desc = "货代修改货代运费报价", result = true)
    @PostMapping("/customerUpdate")
    @ApiOperation(value = "货代修改货代运费报价",notes = "" +
            "id:运费报价id 必填\n" +
            "province:省\n" +
            "city:市\n" +
            "district:县区\n" +
            "town:镇\n" +
            "address:详细地址\n" +
            "dock:码头\n" +
            "boxType:箱型\n" +
            "contact:联系人\n" +
            "contactPhone:联系电话\n" +
            "remark:备注\n" +
            "{\"id\":\"195\",\n" +
            "\"province\":\"省\",\n" +
            "\"city\":\"市\",\n" +
            "\"district\":\"县区\",\n" +
            "\"town\":\"镇\",\n" +
            "\"address\":\"详细地址\",\n" +
            "\"dock\":\"码头\",\n" +
            "\"boxType\":\"箱型\",\n" +
            "\"contact\":\"lxr\",\n" +
            "\"contactPhone\":\"1313131131\",\n" +
            "\"remark\":\"备注\",\n" +
            "\"addressFactoryList\":[{\"id\":\"2\",\"faddress\":\"11\",\"fphone\":\"21\"},{\"id\":\"3\",\"faddress\":\"111\",\"fphone\":\"221\"}]}\n" +
            "",httpMethod = "POST")
    public JsonResult customerUpdate(@RequestBody Address address, HttpServletRequest request) {
        return addressService.customerUpdate(address, getLoginUser());
    }

    /**
     * 修改运费报价(price) 不需要了
     */
    /*@PreAuthorize("hasAuthority('')")
    @OperLog(value = "运费报价", desc = "")*/
    /*@PostMapping("/updatePrice")
    @ApiOperation(value = "修改货代运费报价(price)",notes = "" +
            "id:运费报价id 必填\n" +
            "price:价格\n" +
            "",httpMethod = "POST")
    */
    public JsonResult updatePrice(Address address, HttpServletRequest request) {
        return addressService.updatePrice(address, getLoginUser());
    }

    /**
     * 审核运费报价状态(state)
     */
    @PreAuthorize("hasAuthority('orderB:address:update')")
    @OperLog(value = "货代运费报价", desc = "审核运费报价状态", result = true)
    @PostMapping("/updateState")
    @ApiOperation(value = "审核运费报价状态",notes = "" +
            "id:运费报价id 必填\n" +
            "",httpMethod = "POST")
    public JsonResult updateState(Address address, HttpServletRequest request) {
        return addressService.updateState(address, getLoginUser());
    }

    /**
     * 删除运费报价
     */
    @PreAuthorize("hasAuthority('orderB:address:remove')")
    @OperLog(value = "货代运费报价", desc = "删除")
    @PostMapping("/remove")
    @ApiOperation(value = "删除货代运费报价",notes = "id:id必填",httpMethod = "POST")
    public JsonResult remove(Address address, HttpServletRequest request) {
        return addressService.remove(address, getLoginUser());
    }

}
